package com.certification.controller;

import com.certification.common.utils.Constant;
import com.certification.service.CertificationService;
import com.certification.service.SysUserRoleService;
import com.certification.vo.ResponseMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author copa
 * @createDate 2022-03-30 21:56
 * @function
 */
@RestController
@Api(tags = {"流程：结论认定"})
public class CertResultController extends AbstractController {

    @Resource
    private CertificationService certificationService;

    @Resource
    private SysUserRoleService sysUserRoleService;

    @GetMapping("cert/result")
    @ApiOperation(value = "结论认定")
    public ResponseMessage<String> certResult(Integer certId) {
        for (Long roleId : sysUserRoleService.queryRoleIdList(getUser().getUserId())) {
            if (roleId == Constant.ROLE_PRINCIPAL) {
                return certificationService.certResult(certId, Math.toIntExact(getUserId()));
            }
        }
        return ResponseMessage.errorMsg("该角色不能调用该接口~");
    }
}
